package com.huadao.pda.project.projectList;

import com.huadao.pda.data.bean.Project;
import com.huadao.pda.data.http.RockBaseObserver;
import com.huadao.pda.modle.ProjectModel;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Observable;

public class ProjectPresenter extends IProjectListContract.IProjectListPresenter {

    private ProjectModel projectModel;
//    private int page=1;
//    private int size=20;
//    private int totalSize;

    public ProjectPresenter(IProjectListContract.IProjectListView baseView) {
        attachView(baseView);
        projectModel=new ProjectModel(baseView.getContext());
    }

    @Override
    void getProjectList() {
        Observable<List<Project>> observable = projectModel.getAllProject();
        projectModel.toSubscribe(observable, new RockBaseObserver<List<Project>>(this, null) {
            @Override
            protected void onBaseNext(List<Project> projectList) {
                baseView.onGetProjectList(projectList);
//                ProjectPresenter.this.size=projectList.getPageSize();
//                ProjectPresenter.this.page=projectList.getPage();
//                ProjectPresenter.this.totalSize=projectList.getTotalCount();
            }
        });
//        baseView.onGetProjectList(projectList);
    }

    @Override
    public void searchProjectList(String condition) {
        Observable<List<Project>> observable = projectModel.queryProject(condition);
        projectModel.toSubscribe(observable, new RockBaseObserver<List<Project>>(this, "正在查询") {
            @Override
            protected void onBaseNext(List<Project> projectList) {
                baseView.onGetProjectList(projectList);
            }
        });
    }
}
